home *** CD-ROM | disk | FTP | other *** search
- /*****************************************************************************
- *
- * Program Name:jsuper,jsubmit,jserver
- *
- * Filename:genjob.c
- *
- * Date Created:2/2/89
- *
- * Version: 1.0
- *
- * Programmers:Greg Peto
- *
- * Files used:
- *
- * Date Modified:
- *
- * Modifications:
- *
- * Comments:This file contains routines used by all the job server
- * utilities.
- *
- ****************************************************************************/
-
- /* functions in this file:
- GetArg()
- FindJobServer()
- CheckServerForQueue()
- */
- #include"genjob.h"
- #include<time.h>
- #include<string.h>
- #include<ctype.h>
-
- /* constants definitions */
- /* global variables and data types */
- char *jobQueueName= JOB_QUEUE_NAME;/* name of job queue
- bindery object */
- int jobQueueType= OT_JOB_QUEUE;/* Object type to be used
- when scanning bindery */
- BYTE jobServerConID;/* server with target queue */
- long jobQueueID; /* bindery object ID of
- job queue */
- /* module specific varables and data types */
- /* macro definitions */
-
- /*****************************************************************************/
-
- int ScanArg(arg,command_args,num_args,argString,argInt,argTime,argDate)
- /* Descrip:
- This function scans arg trying to parse off a known command.
- Assumes that arg should be a command line argument.
- Assumes that all legal integer, time or date arguments >= 0.
- It returns the command token value from command_args, if successful,
- along with arguments.
- It calls badUsage() if error detected, which does not return.
- Algorithm://
- */
- /* Input: */
- char *arg; /* element of argv, assumes past '/' */
- COMMAND_ARGScommand_args[];/* possible command line arguments */
- int num_args; /* length of command_args[] */
-
- /* Output: */
- char *argString;/* command argument variable buffer */
- long *argInt;/* numeric argument variable */
- JOB_TIME*argTime;/* hour (0-23):minute (0-59).second (0-59) format */
- JOB_DATE*argDate;/* month (1-12)/day (1-31) /year (1900 + default)
- format */
-
- { /* ScanArg // */
- int i;
- BOOLEANhasEqual;
- char argCom[MAX_COM_KEY];/* command keyword buffer */
- char errorBuffer[128];
- /*--------------------------------------------------main body */
- GetArg(arg,argCom,&hasEqual,argString,argInt,argTime,argDate);
- for (i = 0; i < num_args; ++i)
- {
- if (strlen(argCom) < command_args[i].num_sig)
- continue; /* not long enouph to check */
- if (strncmp(argCom,command_args[i].com_key,strlen(argCom)) == 0)
- { /* matched command keyword, verify args to command */
- #if 0/* may have optional parameters that are not required */
- if ((command_args[i].req_string == FALSE AND
- command_args[i].req_int == FALSE) AND hasEqual)
- sprintf("Warning: command argument %s takes no parameters, parameters ignored.\n",
- command_args[i].com_key);
- else
- #endif
- if ((command_args[i].req_string AND argString[0] == '\0') OR
- (command_args[i].req_int AND *argInt == -1))
- {
- sprintf(errorBuffer,"Command line %s argument parameter incorrect",
- command_args[i].com_key);
- badUsage(errorBuffer);
- }
-
- return(command_args[i].com_token);/* successful */
- } /* end of if strncmp() */
- }
- badUsage("Unrecognized command line argument");
- } /* end of ScanArg */
-
- /********************************************************************/
-
- void GetArg(arg,argCom,hasEqual,argString,argInt,argTime,argDate)
- /* Descrip:
- This function pulls the command line keyword, and comand line
- args out of argv and puts them in argCom, argString, and argInt.
- If argInt returned -1 integer parameter did not start with a digit.
- Both argCom and argString are mapped to upper case.
- Algorithm://
- */
- /* Input: */
- char*arg; /* element of argv, assumes past '/' */
-
- /* Output: */
- char *argCom;/* command keyword buffer */
- BOOLEAN*hasEqual;/* '=' character found in argument */
- char *argString;/* command argument variable buffer */
- long *argInt;/* numeric argument variable */
- JOB_TIME*argTime;/* hour (0-23):minute (0-59).second (0-59) format */
- JOB_DATE*argDate;/* month (1-12)/day (1-31) /year (1900 + default)
- format */
- { /* GetArg // */
- int cnt;
- time_t ltime;/* parameter to time() */
- struct tm*ldate;/* struct needed for localtime() call */
- char *subptr;/* ptr to sub-string */
- /*--------------------------------------------------main body */
- argString[0]= '\0';
- *argInt = -1;
- memset(argTime,-1,sizeof(argTime));
- memset(argDate,-1,sizeof(argDate));
-
- for (cnt = 0;
- *arg NOT= '=' AND *arg AND cnt < MAX_COM_KEY;
- ++arg,++argCom, ++cnt)
- *argCom= toupper(*arg);
- *argCom= '\0';
-
- if (*arg++ NOT= '=')
- *hasEqual= FALSE;
- else
- { /* found '=', skip it and continue */
- *hasEqual= TRUE;
- strcpy(argString,arg);
- strupr(argString);
- if (isdigit(*arg))
- {
- *argInt = argTime->hour = argDate->month= atol(arg);
-
- /* try to pull out time */
- argTime->minute= 0;
- argTime->second= 0;
- if (subptr = strchr(arg,':'))
- if (isdigit(*(++subptr)))
- { /* assume have minute */
- argTime->minute= atoi(subptr);
- if (subptr = strchr(subptr,'.'))
- if (isdigit(*(++subptr)))
- /* assume have second */
- argTime->second= atoi(subptr);
- else
- argTime->second= 0;
- }
-
- /* try to pull out date */
- time(<ime);
- ldate = localtime(<ime);/* get local time for defaults */
- argDate->day= ldate->tm_mday;
- argDate->year= ldate->tm_year;
- if (subptr = strchr(arg,'/'))
- if (isdigit(*(++subptr)))
- { /* assume have day */
- argDate->day= atoi(subptr);
- if (subptr = strchr(subptr,'/'))
- if (isdigit(*(++subptr)))
- /* assume have year */
- if ((argDate->year= atoi(subptr)) > 1900)
- argDate->year-= 1900;
- }
- } /* end of isdigit */
- } /* end of found '=' */
- } /* end of GetArg */
-
- /********************************************************************/
-
- void FindJobServer(queueServerName,mustHaveQueue)
- /* Descrip:
- This function will attempt to find a connection that matches
- the specified server name, or the first one with a bindery
- object of the correct name.
- It will attempt to find the job queue on the server and put it
- its object ID in jobQueueID and it will try to put connection ID
- of the server in jobServerConID.
- Assumes queueServerName is a valid array, but if the 1st character
- is '\0' then it is ignored and all attached servers are searched
- for a valid job queue.
- Algorithm://
- */
- /* Input: */
- char queueServerName[];/* optional name of server to look for queue in */
- BOOLEANmustHaveQueue;/* abort program if queue not found */
-
- /* Output: */
-
- { /* FindJobServer // */
- intccode;
- longCheckServerForQueue();
- /*--------------------------------------------------main body */
- jobServerConID= -1;/* set sentinel value so can tell if found */
- if (queueServerName[0])
- {
- if (ccode = GetConnectionID(queueServerName,&jobServerConID))
- switch (ccode)
- {
- caseNOT_ATTACHED_TO_SERVER:
- /* ? Is this all I need to do to attach ? */
- if (AttachToFileServer(queueServerName,&jobServerConID))
- {
- printf("Could not attach to server %s\n",queueServerName);
- exit(1);
- }
- break;
- caseUNKNOWN_FILE_SERVER:
- printf("Cannot submit to unknown file server %s.\n",
- queueServerName);
- exit(1);
- caseSERVER_BINDERY_LOCKED:
- printf("Bindery for server %s locked, cannot submit.\n",
- queueServerName);
- exit(1);
- default:
- printf("Unable to get a connection to server %s\n",
- queueServerName);
- }
- if ((jobQueueID = CheckServerForQueue(jobServerConID)) == NULL AND mustHaveQueue)
- {
- printf("Job queue not found on server %s\n",queueServerName);
- exit(1);
- }
- } else
- for (jobServerConID = 1;jobServerConID <= MAX_SERVER_ATTACHES; ++jobServerConID)
- if (jobQueueID = CheckServerForQueue(jobServerConID))
- break;
- } /* end of FindJobServer */
-
- /********************************************************************/
-
- long CheckServerForQueue(conID)
- /* Descrip:
- This function checks the server at given connection ID for a legal
- queue to recieve job. If successfull, it returns the object ID
- of the queue in the bindery of the server.
- Algorithm://
- BUGS:
- Currently no steps are taken to make sure the conID passed to
- SetPreferredConnectionID is defined. It will work correctly
- as currently coded, but goes to the default server if conID
- not defined and this may not be desirable.
- */
- /* Input: */
- WORDconID;
- /* Output: */
-
- { /* CheckServerForQueue // */
- longobjectID;
- intccode;
- /*--------------------------------------------------main body */
- if (IsconnectionIDInUse(conID) == FALSE)
- return(NULL);
-
- objectID = -1;
- SetPreferredConnectionID(conID);
- ccode = GetBinderyObjectID(jobQueueName,OT_JOB_QUEUE,&objectID);
- if ( (ccode == 0) && (objectID != -1) )
- return(objectID);
- else
- return(NULL);
- } /* end of CheckServerForQueue */
-
- /********************************************************************/